package com.multithreading.algorithm;

/**
 * @author zx
 * @version 1.0
 * @package_name: com.multithreading.algorithm
 * @date 2024/6/19 18:23
 */
public class Array_test007 {
    public static void main(String[] args) {
        int[] arr = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};

        // 删除指定元素
        int deleteIndex = 4;
        // 不建新数组
        for (int i = deleteIndex; i < arr.length - 1; i++) {
            arr[i] = arr[i + 1];
        }
        // 删除最后一个元素
        arr[arr.length - 1] = 0;

        for (int i : arr) {
            System.out.print(i + " ");
        }

        System.out.println();
        // 方式2
        int[] arr2 = new int[arr.length - 1];
        for (int i = 0; i < arr.length - 1; i++) {
            if (i != deleteIndex) {
                arr2[i] = arr[i];
            } else {
                arr2[i] = arr[i + 1];
            }
        }
        for (int i : arr2) {
            System.out.print(i + " ");
        }

    }
}
